package com.zxy.springboot_vue.kafka;

import com.alibaba.fastjson.JSONObject;
import com.zxy.springboot_vue.common.SendMsgUtil;
import com.zxy.springboot_vue.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Auther: lenovo
 * @Date: 2021/10/28 14:55
 * @Description:
 */
@Component
@Slf4j  //开启日志管理的注解
public class MsgListener {

    /*@Autowired
    private SendMsgUtil sendMsgUtil;
    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;

    @KafkaListener(topics = "1904a")
    public void onMessage(ConsumerRecord<String, String> data) {
        String value = data.value();
        log.info("进入消费者-------------");
        log.info("value:{}",value);

        User user = JSONObject.parseObject(value,User.class);
        if(user!=null){
            // 创建查询对象
            IndexQuery build = new IndexQueryBuilder().withId(user.getId()+ "")
                    .withObject(user).build();


            elasticsearchTemplate.index(build);
        }



        if(value.equals("msg")){
            sendMsgUtil.sendTextEmail("2918446619@qq.com","我劝你善良","当个人吧,小伙子");
        }
    }*/
}
